package com.drinks.yiniang.common.time;

import android.os.CountDownTimer;

/**
 * Created by han on 2019/1/15 0015.
 */

public class TimeCount extends CountDownTimer {

    private MyCountDownListener mCountDownListener;

    /**
     * @param millisInFuture    The number of millis in the future from the call
     *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
     *                          is called.
     * @param countDownInterval The interval along the way to receive
     *                          {@link #onTick(long)} callbacks.
     */
    public TimeCount(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);//参数依次为总时长,和计时的时间间隔
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if(mCountDownListener != null) {
            mCountDownListener.onTimerTick(millisUntilFinished);
        }
    }

    @Override
    public void onFinish() {
        if(mCountDownListener != null) {
            mCountDownListener.onTimerFinish();
        }
    }

    public interface MyCountDownListener {
        void onTimerTick(long millisUntilFinished);
        void onTimerFinish();
    }

    public void setCountDownListener(MyCountDownListener mCountDownListener) {
        this.mCountDownListener = mCountDownListener;
    }
}
